<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单据提交列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="msg"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="statusCode">
                                    <option value=1>提交</option>
                                </select>
                            </li>
                            <li>
                                <label>科室：</label>
                                <select name="deptId">
                                    <option th:each="dept:${depts}" th:value="${dept.deptId}" th:text="${dept.deptName}" ></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>

         <div class="modal inmodal fade" id="myModal8" tabindex="-1" role="dialog" aria-hidden="true">
             <div class="modal-dialog modal-sm">
                 <div class="modal-content">
                     <div class="modal-header">
                         <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                         </button>
                         <h4 class="modal-title">驳回原因</h4>
                     </div>
                     <div class="modal-body">
                         <input type="hidden" id="workId3"/>
                         <textarea id="note" class="form-control m-b" ></textarea>
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                         <button type="button" class="btn btn-primary" onclick="reback()">确定</button>
                     </div>
                 </div>
             </div>
         </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:flow:edit')}]];
        var editNoteFlag = [[${@permission.hasPermi('system:flow:editNote:view')}]];
        var removeFlag = [[${@permission.hasPermi('system:flow:remove')}]];
        var prefix = ctx + "system/flow";
        function updateStutusById(ids,status) {
            $.ajax({
                url: prefix+"/updateStatus?ids="+ids+"&status="+status,
                cache: false,
                contentType: false,
                processData: false,
                type: 'GET',
                success: function (result) {
                    $("#bootstrap-table").bootstrapTable('refresh');
                    layer.alert(result);
                }
            });
        }



        function updateStutus(id,status,name,title) {
            var title;
            if(status==2) {
                title = "确定要审核"+name+"提交的["+title+"]需求吗？";
            } else if(status==3) {
                $("#workId3").val(id);
                $("#myModal8").modal("show");
                return;
            }
            $.modal.confirm(title, function() {
                $.ajax({
                    url: prefix+"/updateStatus?ids="+id+"&status="+status,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'GET',
                    success: function (result) {
                        $("#bootstrap-table").bootstrapTable('refresh');
                        $.modal.alertSuccess(result);
                    }
                });
            });
        }

      function editNoteOpen(workId){
             var url= prefix+"/editNote?workId="+workId;
             $.modal.openTab("查看", url);

        }
        function reback() {
            var workId = $("#workId3").val();
            var note = $("#note").val();
            debugger;
            $.ajax({
                url: prefix+"/addNote?note="+note+"&workId="+workId,
                cache: false,
                contentType: false,
                processData: false,
                type: 'post',
                success: function (result) {
                    $("#note").val("");
                    $("#myModal8").modal("hide");
                    $.ajax({
                        url: prefix+"/updateStatus?ids="+workId+"&status=3",
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'GET',
                        success: function (result) {
                            $("#bootstrap-table").bootstrapTable('refresh');
                            $.modal.alertSuccess(result);
                        }
                    });
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/listWithAuth",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "单据提交",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'workId',
                    title: '',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '科室名称'
                },
                {
                    field: 'title',
                    title: '标题'
                },
                    {
                        field: 'euFreq',
                        title: '频次',
                        formatter: function (value, item, index) {
                            if (item.euFreq == 1) {
                                return "小于一月";
                            } else if (item.euFreq == 2) {
                                return "小于一季";
                            } else if (item.euFreq == 3) {
                                return "小于一年";
                            } else if (item.euFreq == 4) {
                                return "仅此一次";
                            }
                        }
                    },
                    {
                        field: 'fgUrgent',
                        title: '加急标志',
                        formatter: function (value, item, index) {
                            if (item.fgUrgent == 0) {
                                return "正常";
                            } else if (item.fgUrgent == 1) {
                                return "<span style='color:red'>加急</span>";
                            }
                        }
                    },
                {
                   field: 'statusCode',
                   title: '状态',
                        formatter: function (value, item, index) {
                            if (item.statusCode == 0) {
                                return "新建";
                            } else if (item.statusCode == 1) {
                                return "<span style='color:red'>提交</span>";
                            } else if (item.statusCode == 2) {
                                return "<span style='color:red'>已审核</span>";
                            } else if (item.statusCode == 3) {
                                return "<span style='color:red'>驳回</span>";
                            }
                        }
                },
                {
                    field: 'naEmpCre',
                    title: '创建人'
                },
                {
                    field: 'dtSysCre',
                    title: '创建日期'
                },
                {
                    field: 'lastDate',
                    title: '最后日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.statusCode == 1) {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="editNoteOpen(\'' + row.workId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="updateStutus(\'' + row.workId + '\',2,\''+row.naEmpCre+'\',\''+row.title+'\')"><i class="fa fa-check"></i>审核</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="updateStutus(\'' + row.workId + '\',3,\''+row.naEmpCre+'\',\''+row.title+'\')"><i class="fa fa-remove"></i>驳回</a> ');
                        }
                         return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>